﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ranking : MonoBehaviour {
    public static Ranking instance;
    public GameObject GridPanel;
    public GameObject RankItmePrefab;
	// Use this for initialization
	void Start () {
        // InitRankItem();
        instance = this;
    }
	
	// Update is called once per frame
	void Update () {
       
	}
    ////void OnGUI()
    ////{
    ////    if( GUI.Button( new Rect( 0, 0, 100, 100 ), "TEST" ) )
    ////    {
    ////        InitRankItem();
    ////    }
    ////}
    public void InitRankItem()
    {
        foreach( Transform child in GridPanel.transform )
        {
            Destroy( child.gameObject );
        }
        float x = RankItmePrefab.transform.position.x;
        float y = RankItmePrefab.transform.position.y;
        for( int i = 0; i < 50; i++ )
        {
            GameObject go = Instantiate( RankItmePrefab );
            go.transform.parent = GridPanel.transform;
            go.name = "RankItem" + i;
            string id = ( i + 1 ).ToString();
            go.transform.Find( "Ranking" ).GetComponent<UILabel>().text = InitConfig.instance.RankConfigDictionary[id].rank;
            go.transform.Find( "Name" ).GetComponent<UILabel>().text = InitConfig.instance.RankConfigDictionary[id].name;
            go.transform.Find( "Grade" ).GetComponent<UILabel>().text = InitConfig.instance.RankConfigDictionary[id].grade;
            go.transform.localPosition = new Vector3( x, y - i * 130 );
            go.transform.localScale = new Vector3( 1, 1 );
        }
    }
}
